﻿
Imports System.IO

Public Module strmid
    Public Sub main(ByVal args() As String)
        If args.Length() < 4 Then
            raiseError("argument count error, input output start length, " + _
                        "if input or output is " + consoleIOArgument + ", use console.", errorHandle.errorType.critical)
        Else
            Dim reader As TextReader = Nothing
            Dim writer As TextWriter = Nothing
            assert(initialInput(args(0), reader), "file no found " + args(0))
            assert(initialOutput(args(1), writer), "file no found " + args(1))

            Dim start As Int64
            Dim length As Int64
            assert(convertor.toint64(args(2), start), "cannot convert " + args(2) + " to int64 for start.")
            assert(convertor.toint64(args(3), length), "cannot convert " + args(3) + " to int64 for length.")

            Dim input As String = Nothing
            input = reader.ReadLine()
            While Not input Is Nothing
                writer.WriteLine(stringUtils.strmid(input, start, length))
                input = reader.ReadLine()
            End While

            closereader(reader)
            closewriter(writer)
        End If
    End Sub
End Module
